/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.comfacauca.xmlc2.servlet;

import com.comfacauca.xmlc2.dao.ProyectosDAO;
import com.comfacauca.xmlc2.entidades.Actividad;
import com.comfacauca.xmlc2.entidades.Iteracion;
import com.comfacauca.xmlc2.entidades.Proyecto;
import com.comfacauca.xmlc2.entidades.Responsable;
import com.comfacauca.xmlc2.servicio.ProyectosI;
import com.comfacauca.xmlc2.utils.Utiles;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author eorozco
 */
public class ActividadServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    
    ProyectosI proyectosI = new ProyectosDAO();
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        Actividad actividad = new Actividad();        
        actividad.setId(0);
        Date fecha1 = Utiles.stringToDate1(request.getParameter("fecha"));
        actividad.setFecha(fecha1);
        actividad.setTiempo(Float.parseFloat(request.getParameter("tiempo")));
        actividad.setTicket(Integer.parseInt(request.getParameter("ticket")));
        actividad.setIdArea(Integer.parseInt(request.getParameter("area")));
        actividad.setIdTipoactividad(Integer.parseInt(request.getParameter("tactividad")));
        HttpSession session = request.getSession();
        Integer idautor = (Integer) session.getAttribute("id");
        //Responsable autor = new Responsable(idautor);        
        actividad.setIdResponsable(idautor);
        actividad.setDescripcion(request.getParameter("descripcion"));
        int motivo = ("".equals(request.getParameter("motivoextra1")))?0:Integer.parseInt(request.getParameter("motivoextra1"));
        String sevenet = ("".equals(request.getParameter("sevenet1")))?"NA":request.getParameter("sevenet1");
        String obsextra = ("".equals(request.getParameter("obsextra1")))?"NA":request.getParameter("obsextra1");                              
        actividad.setIdMotivoextra(motivo);
        actividad.setSevenet(sevenet);
        actividad.setObsextra(obsextra);               
        
        proyectosI.setActividad(actividad);
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
